package inits

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"red/global"
	"red/intermal/model"
)

func GetMysql() {
	var err error
	//data := appconfig.Config.Mysql
	// refer https://github.com/go-sql-driver/mysql#dsn-data-source-name for details
	//dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", data.Username, data.Password, data.Host, data.Port, data.Database)
	dsn := "root:052A73AC8C5671BD2AAB6B8F18903E12@tcp(14.103.200.140:3306)/2303A?charset=utf8mb4&parseTime=True&loc=Local"
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	log.Println("mysql 连接成功")
	err = global.DB.AutoMigrate(&model.User{}, &model.Video{}, &model.Comment{})
	if err != nil {
		panic(err)
	}
	log.Println("mysql 迁移成功")

}
